package com.vichat.common.signal;
import com.alibaba.fastjson.JSONObject;
import com.vichat.common.cache.RedisHelper;
import com.vichat.common.constant.GlobalConstant;
import com.vichat.common.rudp.CmdDefine;
import com.vichat.common.util.NumberUtils;
import com.vichat.common.util.StringUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.HashMap;

public class CmdUtil {
    protected static transient final Logger log = LoggerFactory.getLogger(CmdUtil.class);

    /**
     cmd_param_cmd_type   cmd_type_send_msg
     cmd_param_snd_id     10000
     cmd_param_rcv_id     xxxxxx
     cmd_param_mid        xxxxxxxxx
     cmd_param_time       xxxxxxx
     cmd_param_msg_type   xxxx
     cmd_param_msg        xxxxxxx
    **/
    public static void sendImMsg(long sndId, long rcvId, long rid, String msgType, String msg){
        HashMap<String, String> req = new HashMap<>();
        req.put(String.valueOf(CmdDefine.cmd_param_cmd_type), String.valueOf(CmdDefine.cmd_type_send_msg));
        req.put(String.valueOf(CmdDefine.cmd_param_snd_id), String.valueOf(sndId));
        if(NumberUtils.isNotNullOrZero(rcvId)){
            req.put(String.valueOf(CmdDefine.cmd_param_rcv_id), String.valueOf(rcvId));
        }
        if(NumberUtils.isNotNullOrZero(rid)){
            req.put(String.valueOf(CmdDefine.cmd_param_rid), String.valueOf(rid));
        }
        req.put(String.valueOf(CmdDefine.cmd_param_mid), StringUtil.generateMid());
        req.put(String.valueOf(CmdDefine.cmd_param_time), String.valueOf(System.currentTimeMillis()));
        req.put(String.valueOf(CmdDefine.cmd_param_msg_type), msgType);
        req.put(String.valueOf(CmdDefine.cmd_param_msg), msg);
        RedisHelper.imsQueue(GlobalConstant.IMS_EVENT_QUEUE, JSONObject.toJSONString(req));
    }

    /**
     cmd_param_cmd_type   cmd_type_room_msg
     cmd_param_snd_id     10000
     cmd_param_rcv_id     xxxxxx
     cmd_param_mid        xxxxxxxxx
     cmd_param_time       xxxxxxx
     cmd_param_msg_type   xxxx
     cmd_param_msg        xxxxxxx
     cmd_param_rid        xxxxx
     **/
    public static void sendRoomMsg(long sndId, long rcvId, long rid, String msgType, String msg){
        HashMap<String, String> req = new HashMap<>();
        req.put(String.valueOf(CmdDefine.cmd_param_cmd_type), String.valueOf(CmdDefine.cmd_type_room_msg));
        req.put(String.valueOf(CmdDefine.cmd_param_snd_id), String.valueOf(sndId));
        if(NumberUtils.isNotNullOrZero(rcvId)){
            req.put(String.valueOf(CmdDefine.cmd_param_rcv_id), String.valueOf(rcvId));
        }
        req.put(String.valueOf(CmdDefine.cmd_param_rid), String.valueOf(rid));
        req.put(String.valueOf(CmdDefine.cmd_param_mid), StringUtil.generateMid());
        req.put(String.valueOf(CmdDefine.cmd_param_time), String.valueOf(System.currentTimeMillis()));
        req.put(String.valueOf(CmdDefine.cmd_param_msg_type), msgType);
        req.put(String.valueOf(CmdDefine.cmd_param_msg), msg);
        RedisHelper.gmsQueue(GlobalConstant.GMS_EVENT_QUEUE, JSONObject.toJSONString(req));
    }


    public static void main(String[]args) {
        CmdUtil util = new CmdUtil();
        //util.sendImMsg(10000,300000001,GlobalConstant.IMS_MSG_TYPE_10000,"test");
    }
}
